package campeonatofutebol.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import campeonatofutebol.util.CarregandoFeedsTask;

import com.example.campeonatofutebol.R;

public class ClassificacaoList extends Activity {
	
	public static TextView textView;
	public static TableLayout table;
	public static View v;
	private CarregandoFeedsTask c;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.classificacao_tablelayout);
		c = new CarregandoFeedsTask(ClassificacaoList.this);
		c.execute("");
	}

	public void formatarTabela() {
		TableLayout t = (TableLayout) this.findViewById(R.id.tableLayout1);
		ArrayList<String> classificacao = (ArrayList<String>) c.getResult();
		for(int index = 0; index < classificacao.size(); index++){
			String[] stringDividida = classificacao.get(index).split(" ");
			textView = new TextView(this);
			TableRow rowAtual = new TableRow(t.getContext());
			textView.setTextColor(Color.WHITE);
			textView.setTypeface(Typeface.DEFAULT_BOLD);
			textView.setTextSize(16);
			if(index == 0){
				textView.setTextColor(Color.parseColor("#ffCCCC22"));
				textView.setGravity(Gravity.CENTER_HORIZONTAL);
				textView.setText("Pos  ");
				rowAtual.addView(textView);
				textView = new TextView(this);
				textView.setTextColor(Color.parseColor("#ffCCCC22"));
				textView.setTypeface(Typeface.DEFAULT_BOLD);
				textView.setTextSize(16);
				textView.setText(stringDividida[0] + "  ");
				rowAtual.addView(textView);
				for(int index2 = 1; index2 < stringDividida.length; index2++){
					textView = new TextView(this);
					textView.setTextColor(Color.parseColor("#ffCCCC22"));
					textView.setTypeface(Typeface.DEFAULT_BOLD);
					textView.setTextSize(16);
					textView.setText(stringDividida[index2] + "  ");
					rowAtual.addView(textView);
				}
			}
			else{
				int inicio = 2;
				textView.setGravity(Gravity.NO_GRAVITY);
				textView.setText(stringDividida[0]);
				rowAtual.addView(textView);
				textView = new TextView(this);
				textView.setTextColor(Color.WHITE);
				textView.setTypeface(Typeface.DEFAULT_BOLD);
				textView.setTextSize(16);
				if(stringDividida.length == 11){
					textView.setText(stringDividida[1] + "  ");
				}
				else{
					if(stringDividida[1].equals("Boa") && stringDividida[2].equals("Esporte")){
						inicio = 4;
						textView.setText(stringDividida[1] + " " + stringDividida[2]  + "  ");
					}
					else{
						inicio = 3;
						textView.setText(stringDividida[1] + " " + stringDividida[2] + "  ");
					}
				}
				rowAtual.addView(textView);
				for(int index2 = inicio; index2 < stringDividida.length; index2++){
					textView = new TextView(this);
					textView.setTextColor(Color.WHITE);
					textView.setTextSize(16);
					textView.setText(stringDividida[index2] + "  ");
					rowAtual.addView(textView);
				}
			}
			t.addView(rowAtual);
			View v = new View(this);
			v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 2));
			v.setBackgroundColor(Color.parseColor("#ffCCCC22"));
			t.addView(v);
			
		}
	}
	
}
